import { defineStore } from "pinia";

// 供应商表单数据
const getSupplierDefaultData = () => ({
  supplier_id: null,
  name: "",
  contact_person: "",
  contact_phone: "",
  address: "",
  bank_name: "",
  bank_account: "",
  rating_level: null,
  category_ids: [],
  note: "",
  status: 1,
});

export const SupplierTempStore = defineStore("supplier-temp-store", {
  state: () => ({
    // 存储用户上次未保存的表单数据
    tempFormData: getSupplierDefaultData(),
  }),

  actions: {
    saveTempData(data) {
      this.tempFormData = JSON.parse(JSON.stringify(data));
    },

    clearTempData() {
      this.tempFormData = getSupplierDefaultData();
    },
  },
  persist: {
    key: "supplier-form-temp-data",
    storage: localStorage,
  },
});
